package com.quanquan.management.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.quanquan.management.dto.UserDisCountDTO;
import com.quanquan.management.request.UserDisCountRequest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import utils.Request;

/**
 * @ClassName:UserDisCountService
 * @Description:TODO
 * @Author:xiongjunbao
 * @Date:2019/12/30 18:14
 * @Version 1.0
 */
@Service
public class UserDisCountService {


    @Value("${module-url.parkingUrl}")
    private String parkingUrl;

    public UserDisCountDTO list(UserDisCountRequest requestBody) {
        String json = Request.postJson(parkingUrl + "ketop_parking/user_discount_back", requestBody);
        UserDisCountDTO data = null;
        JSONObject jsonObject = JSON.parseObject(json);
        if (null == jsonObject) {
            return data;
        }
        Integer resCode = jsonObject.getInteger("resCode");
        if (0 == resCode) {
            data = jsonObject.getJSONObject("data").toJavaObject(UserDisCountDTO.class);
            return data;
        }
        return data;
    }

    public UserDisCountDTO findById() {
        UserDisCountRequest requestBody = new UserDisCountRequest();
        String json = Request.postJson(parkingUrl + "ketop_parking/user_discount_back", requestBody);
        JSONObject jsonObject = JSONObject.parseObject(json);
        Integer resCode = jsonObject.getInteger("resCode");
        UserDisCountDTO adminDTO = null;
        if (0 == resCode) {
            JSONObject data = jsonObject.getJSONObject("data");
            adminDTO = data.toJavaObject(UserDisCountDTO.class);
        }
        return adminDTO;
    }


    public boolean update(UserDisCountRequest requestBody) {
        if (null == requestBody) {
            return false;
        }
        String json = Request.postJson(parkingUrl + "ketop_parking/update_user_discount", requestBody);
        JSONObject jsonObject = JSONObject.parseObject(json);
        Integer resCode = jsonObject.getInteger("resCode");
        if (0 == resCode) {
            return true;
        }
        return false;
    }


}
